package com.sinux.mms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinux.mms.entity.Member;
import com.sinux.mms.entity.Syslog;
import com.sinux.mms.service.SyslogServiceI;

/**
 * 日志管理
 * @Description 
 * @author w.g
 * @date 2017-10-17 16:43:24
 */
@Controller
@SuppressWarnings("all")
public class SyslogController {
	@Autowired
	private SyslogServiceI syslogService;
	/**
	 * 查找全部日志
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/syslogtab")
	public Map<String, Object> syslogTab(HttpServletRequest request,HttpServletResponse response,Model model){
		Map<String, Object> map=new HashMap<String, Object>();
		int offset =Integer.valueOf(request.getParameter("offset")); //当前页第一条数据(包含)  
	    int limit = Integer.valueOf(request.getParameter("limit")); //每页多少条数据  
		//页数=当前页第一条数据/每页多少条数据 +1
	    List<Syslog> syslogs=syslogService.findSyslogPageing(offset/limit+1,limit);
		int total=syslogService.findAllSyslogList().size();
		map.put("rows", syslogs);
		map.put("total", total);
		return map;
	}
	/**
	 * 添加日志
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/addsyslog")
	public  Map<String,Object> addSyslog(HttpServletRequest request,HttpServletResponse response,Syslog model){
		Map<String, Object> map=new HashMap<String, Object>();
		syslogService.addSyslog(model);
		map.put("msg", "成功");
		return map;
	}
	
}
